﻿using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

namespace Peer.Define
{
    public class Parameters
    {
        private readonly BaseConverter peerConverter;

        private readonly List<byte[]> parameters;

        private int index = 0;

        public Parameters(BaseConverter peerConverter, byte[] bytes)
        {
            this.peerConverter = peerConverter;
            parameters = peerConverter.Deserialize<List<byte[]>>(bytes);
        }

        public T Get<T>(int index)
        {
            return peerConverter.Deserialize<T>(parameters[index]);
        }

        public T GetNext<T>()
        {
            return Get<T>(index++);
        }

        public object Get(int index, Type type)
        {
            return peerConverter.DeserializeObject(parameters[index], type);
        }
    }
}
